# coding=utf-8


class EcsTask(object):
    def __init__(self, task_definition_name, version):
        self._provision_default()
        self.taskDefinition = task_definition_name
        self.version = version

    @staticmethod
    def _find_by_node(lst, prop_name, prop_value):
        for item in lst:
            if item[prop_name] == prop_value:
                return item
        raise KeyError("prop_name %s not found..." % prop_name)

    def set_cpu_memory(self, cpu, memory):
        self.overrides['cpu'] = cpu
        self.overrides['memory'] = memory

    def _provision_default(self):
        # self.cluster = 'ptadmin-automation-ec2'
        self.instanceCount = 1
        self.launchType = 'EC2'
        self.networkConfiguration = {
            'awsvpcConfiguration': {
                'subnets': [
                    'subnet-01eaf81149dea2534',
                ],
                'securityGroups': [
                    'sg-0d5d78fbe97ba73c6',
                ],
                'assignPublicIp': 'DISABLED'
            }
        }
        self.overrides = {
                # 'containerOverrides': [
                #     {
                #         'name': 'browse-tree-node-processor',
                #         # 'command': [
                #         #     'string',
                #         # ],
                #         # 'environment': [
                #         #     {
                #         #         'name': 'string',
                #         #         'value': 'string'
                #         #     },
                #         # ],
                #         # 'environmentFiles': [
                #         #     {
                #         #         'value': 'string',
                #         #         'type': 's3'
                #         #     },
                #         # ],
                #         # 'cpu': 123,
                #         # 'memory': 123,
                #         # 'memoryReservation': 123,
                #         # 'resourceRequirements': [
                #         #     {
                #         #         'value': 'string',
                #         #         'type': 'GPU'|'InferenceAccelerator'
                #         #     },
                #         # ]
                #     },
                # ],
                'cpu': '128',
                # 'inferenceAcceleratorOverrides': [
                #     {
                #         'deviceName': 'string',
                #         'deviceType': 'string'
                #     },
                # ],
                # 'executionRoleArn': 'string',
                'memory': '128',
                # 'taskRoleArn': 'string'
            }
            # self.taskDefinition = 'browse-tree-node-processor-task:9'
